package com.hongxun.project.assets.pPicture.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.common.utils.text.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.pPicture.domain.PPicture;
import com.hongxun.project.assets.pPicture.service.IPPictureService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 现场照片 信息操作处理
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/pPicture")
public class PPictureController extends BaseController
{
    private String prefix = "assets/pPicture";
	
	@Autowired
	private IPPictureService pPictureService;
	
	@RequiresPermissions("assets:pPicture:view")
	@GetMapping()
	public String pPicture()
	{
	    return prefix + "/pPicture";
	}

	/*@GetMapping("/task_pPicture/{taskId}")
	public String task_pPicture(@PathVariable("taskId") String taskId , ModelMap modelMap)
	{
		modelMap.put("taskId",taskId);
	    return prefix + "/task-pPicture";
	}*/
	
	/**
	 * 查询现场照片列表
	 */
	@RequiresPermissions("assets:pPicture:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PPicture pPicture)
	{
		startPage();
        List<PPicture> list = pPictureService.selectPPictureList(pPicture);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出现场照片列表
	 */
	@RequiresPermissions("assets:pPicture:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PPicture pPicture)
    {
    	List<PPicture> list = pPictureService.selectPPictureList(pPicture);
        ExcelUtil<PPicture> util = new ExcelUtil<PPicture>(PPicture.class);
        return util.exportExcel(list, "pPicture");
    }
	
	/**
	 * 新增现场照片
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存现场照片
	 */
	@RequiresPermissions("assets:pPicture:add")
	@Log(title = "现场照片", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PPicture pPicture)
	{
		pPicture.setDatastate("新增");
		return toAjax(pPictureService.insertPPicture(pPicture));
	}

	/**
	 * 修改现场照片
	 */
	@GetMapping("/edit/{id}/{taskId}")
	public String edit(@PathVariable("id") String id, @PathVariable("taskId") String taskId, ModelMap mmap)
	{
		PPicture pPicture = pPictureService.selectPPictureByIdForState(id,taskId);
		mmap.put("pPicture", pPicture);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存现场照片
	 */
	@RequiresPermissions("assets:pPicture:edit")
	@Log(title = "现场照片", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PPicture pPicture)
	{
		pPicture.setDatastate("修改");
		return toAjax(pPictureService.updatePPicture(pPicture));
	}
	
	/**
	 * 删除现场照片
	 */
	@RequiresPermissions("assets:pPicture:remove")
	@Log(title = "现场照片", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(pPictureService.deletePPictureByIds(ids));
	}


	/**
	 * 删除现场照片
	 */
	@RequiresPermissions("assets:pPicture:remove")
	@Log(title = "现场照片", businessType = BusinessType.DELETE)
	@PostMapping( "/remove2Id")
	@ResponseBody
	public AjaxResult remove2Id(String ids , String taskIds)
	{
		String[] str = Convert.toStrArray(ids);
		int i = 0;
		for (String s : str) {
			PPicture pPicture = new PPicture();
			pPicture.setId(s);
			pPicture.setTaskId(taskIds);
			pPicture.setDatastate("删除");
			i = pPictureService.updatePPicture(pPicture);
		}
		return toAjax(i);
//		return toAjax(pPictureService.deletePPictureByIdsAndTaskIds(ids , taskIds));
	}

}
